package com.ruoyi.web.controller.teaching;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.teaching.domain.PlatformFZone;
import com.ruoyi.teaching.domain.vo.PlatformFForumVO;
import com.ruoyi.teaching.service.PlatformFForumService;
import com.ruoyi.teaching.service.PlatformFForumUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王旭
 * @since 2024-10-14
 */
@RestController
@RequestMapping("/platform/forum")
@Api(tags = "platform-f-帖子/评论管理")
public class PlatformFForumController {
    @Autowired
    private PlatformFForumService platformFForumService;
    @Autowired
    private PlatformFForumUserService platformFForumUserService;

    /**
     * 分页获取所有帖子
     */
    @GetMapping("/forumList")
    @ApiOperation(value = "分页获取所有帖子", notes = "分页获取所有帖子")
    public AjaxResult forumList(Integer pageNum, Integer pageSize, Integer zoneId, String message, Integer type) {
        return platformFForumService.forumList(pageNum, pageSize, zoneId,message,type);
    }

    /**
     * 后台分页获取所有帖子
     */
    @GetMapping("/backForumList")
    @ApiOperation(value = "后台分页获取所有帖子", notes = "后台分页获取所有帖子")
    public AjaxResult backForumList(Integer pageNum, Integer pageSize, String title, String createBy, Integer zoneId) {
        return platformFForumService.backForumList(pageNum, pageSize, title,createBy,zoneId);
    }

    /**
     * 查找某个帖子下的所有评论
     */
    @GetMapping("/forumCommentList")
    @ApiOperation(value = "查找某个帖子下的所有评论", notes = "查找某个帖子下的所有评论")
    public AjaxResult forumCommentList(Integer forumId,Integer pageNum, Integer pageSize) {
        return platformFForumService.forumCommentList(forumId,pageNum,pageSize);
    }

    /**
     * 查看 帖子/评论/点赞 的帖子详情
     */
    @GetMapping("/detail")
    @ApiOperation(value = "查看 帖子/评论/点赞 的帖子详情", notes = "查看 帖子/评论/点赞 的帖子详情")
    public AjaxResult detail(Integer forumId,Integer type,Integer pageNum, Integer pageSize) {
        return platformFForumService.detail(forumId,type, pageNum, pageSize);
    }

    /**
     * 分页获取和我有关的评论
     */
    @GetMapping("/ownCommentList")
    @ApiOperation(value = "分页获取和我有关的评论", notes = "分页获取和我有关的评论")
    public AjaxResult ownCommentList(Integer pageNum, Integer pageSize, Integer type) {
        return platformFForumService.ownCommentList(pageNum,pageSize,type);
    }

    /**
     * 查询自己所有的帖子
     */
    @GetMapping("/myForumList")
    @ApiOperation(value = "查询自己所有的帖子", notes = "查询自己所有的帖子")
    public AjaxResult myForumList(Integer pageNum, Integer pageSize, Integer zoneId, String time) {
        return platformFForumService.myForumList(pageNum, pageSize, zoneId, time);
    }

    /**
     * 发布帖子/评论
     */
    @PostMapping("/addForumComment")
    @ApiOperation(value = "发布帖子/评论", notes = "发布帖子/评论")
    @Log(title = "【发布帖子/评论】", businessType = BusinessType.INSERT)
    public AjaxResult addForumComment(@RequestBody PlatformFForumVO platformFForumVO) {
        String status = platformFForumUserService.checkForumStatus();
        if(StringUtils.isNotEmpty(status)){
            return AjaxResult.error(status);
        }
        if(null == platformFForumVO.getTopId()){
            if(null == platformFForumVO.getTitle() || "".equals(platformFForumVO.getTitle())){
                return AjaxResult.error("请填写标题");
            }
            if(null == platformFForumVO.getZoneId()){
                return AjaxResult.error("请选择所属分区");
            }
            if(null == platformFForumVO.getMessage() || "".equals(platformFForumVO.getMessage())){
                return AjaxResult.error("请填写内容");
            }
            if(null != platformFForumVO.getImageUrl() && platformFForumVO.getImageUrl().length >9){
                return AjaxResult.error("最多添加9张图片");
            }
        }else {
            if(null == platformFForumVO.getMessage() || "".equals(platformFForumVO.getMessage())){
                return AjaxResult.error("请填写内容");
            }
        }
        return platformFForumService.addForumComment(platformFForumVO);
    }

    /**
     * 批量删除帖子/评论
     */
    @DeleteMapping("/deleteForumComment/{ids}")
    @ApiOperation(value = "批量删除帖子/评论", notes = "批量删除帖子/评论")
    @Log(title = "【批量删除帖子/评论】", businessType = BusinessType.DELETE)
    public AjaxResult deleteForumComment(@PathVariable("ids") Long[] ids) {
        return platformFForumService.deleteForumComment(ids);
    }

}

